<?php

namespace catchAdmin\newsDeclare\controller;

use catchAdmin\newsDeclare\request\PlatformCreateRequest;
use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catcher\CatchAuth;
use catchAdmin\newsDeclare\model\NewsPlatform;
use catchAdmin\basics\request\BusinessTypeCreateRequest;
class Platform extends CatchController
{

    public function __construct(NewsPlatform $platformModel)
    {
        $this->platformModel = $platformModel;
    }

    public function index(CatchAuth $auth)
    {
        $user = $auth->user();
        return CatchResponse::paginate($this->platformModel->getList($user['tenant_id']));
    }

    public function create(CatchAuth $auth,PlatformCreateRequest $request)
    {
        $params = $request->post();
        $user = $auth->user();
        $params['tenant_id'] = $user['tenant_id'];
        return CatchResponse::success($this->platformModel->storeBy($params),"新建成功");
    }

    public function update($id,PlatformCreateRequest $request)
    {
        $params = $request->post();
        return CatchResponse::success($this->platformModel->updateBy($id, $params),"编辑成功");
    }

    public function delete($id,Request $request)
    {
        return CatchResponse::success($this->platformModel->deleteBy($id),'删除成功');
    }
}